/***********************************************************************
 * Module:  SaleChance.java
 * Author:  ZhangYQ
 * Purpose: Defines the Class SaleChance
 ***********************************************************************/

package office.bo.sale.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.action.sale.form.SaleChanceConditionForm;
import office.action.sale.wrapper.SaleChanceWrapper;
import office.bo.sale.ISaleChance;
import office.domainset.BizDomainProviderSetImpl;
import platform.common.bo.Page;
import platform.common.bo.PersistenceBO;
import platform.common.dao.IDomainProvider;
import platform.common.dao.IDomainProviderSet;
import platform.common.exception.BusinessException;
import platform.util.Util;

public class SaleChance extends PersistenceBO implements ISaleChance{
	
	private static final long serialVersionUID = 1L;
	private String chanceName;   //机会名称
	private String customerName; //客户名称
	/**
	 * 机会来源有以下几种
	 * 1、客户主动询价
	 * 2、网上搜索
	 * 3、工作人员拓展
	 * 4、广告宣传
	 * 5、客户介绍
	 * 6、其它
	 */
	private String chanceSource; //机会来源 
	private Date createDate;     //创建日期
	private Date chanceDate;     //机会日期
	private String principal;    //责任人
	private String mark;         //备注

	/**
	 * 
	 * <br/>方法描述:获得分页信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Page getPageInfo(IDomainProviderSet domainProviderSet)throws BusinessException{
		Page page = new Page();
		try{
			BizDomainProviderSetImpl domainProviderSetImpl=(BizDomainProviderSetImpl)domainProviderSet;
			IDomainProvider provider = domainProviderSetImpl.getSaleChanceDP();
			List<SaleChance> list = domainProviderSetImpl.getDao().findAllByDomian(provider);
			int pageSize = Integer.parseInt(Util.parsePropertiesReturnStr("project", "SaleChance.pageSize"));
			page.setPageSize(pageSize);
			if(list.size()%pageSize == 0){
				page.setTotalPage(list.size()/pageSize);
			}else{
				page.setTotalPage(list.size()/pageSize+1);
			}		
		}catch(Exception e){
			throw this.handleBusinessBOException("获得分页信息失败", e);
		}	
		return page;
	}
	
	@SuppressWarnings("unchecked")
	public List<SaleChanceWrapper> findAllSaleChanceByCondition(IDomainProviderSet domainProviderSet,
			SaleChanceConditionForm condition, Page page)
			throws BusinessException {
		List<SaleChanceWrapper> prodSaleChanceWrapperList = null;
		try{
			BizDomainProviderSetImpl domainProviderSetImpl=(BizDomainProviderSetImpl)domainProviderSet;
			IDomainProvider provider = domainProviderSetImpl.getSaleChanceDP();
			Map condMap= new HashMap();
			if(!Util.isNull(condition.getCustomerName())){
				condMap.put("customerName", condition.getCustomerName());
			}
			prodSaleChanceWrapperList = domainProviderSetImpl.getDao().findByDynamicHql(provider, "findSaleChanceByIdAndName", condMap,new HashMap(),page);
		}catch (Exception e) {
			throw this.handleBusinessBOException("获取价格数据列表失败！", e);
		}
		return prodSaleChanceWrapperList;
	}
	
	/**
	 * 
	 * <br/>方法描述:条件查询显示分页信息
	 * @param condition
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public Page getPageInfoByCondition(IDomainProviderSet domainProviderSet,SaleChanceConditionForm condition)throws BusinessException{
		Page page = new Page();
		try {
			BizDomainProviderSetImpl domainProviderSetImpl=(BizDomainProviderSetImpl)domainProviderSet;
			IDomainProvider provider = domainProviderSetImpl.getSaleChanceDP();
			
			int pageSize = Integer.parseInt(Util.parsePropertiesReturnStr("project", "SaleChance.pageSize"));
			page.setPageSize(pageSize);
			Map condMap= new HashMap();
			
			if(!Util.isNull(condition.getCustomerName())){
				condMap.put("customerName", condition.getCustomerName());
			}
 			List list = domainProviderSetImpl.getDao().findByDynamicHql(provider, "findSaleChanceByIdAndName", condMap, new HashMap());
			if(list.size()%pageSize == 0){
				page.setTotalPage(list.size()/pageSize);
			}else{
				page.setTotalPage(list.size()/pageSize+1);
			}
			
		} catch (Exception e) {
			throw this.handleBusinessBOException("获取价格数据列表失败！", e);
		}
		return page;
	}
	
	public String getChanceName() {
		return chanceName;
	}

	public void setChanceName(String chanceName) {
		this.chanceName = chanceName;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getChanceSource() {
		return chanceSource;
	}

	public void setChanceSource(String chanceSource) {
		this.chanceSource = chanceSource;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getChanceDate() {
		return chanceDate;
	}

	public void setChanceDate(Date chanceDate) {
		this.chanceDate = chanceDate;
	}

	public String getPrincipal() {
		return principal;
	}

	public void setPrincipal(String principal) {
		this.principal = principal;
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

}